<?php

namespace app\v6\controller;

use think\Db;
use think\facade\Lang;
use app\models\PcConfig;
use think\Request;

class Config
{
    private $pcConfig;
    protected $request;
    public function __construct(Request $request)
    {
        $this->pcConfig = new PcConfig();
        $this->request = $request;
    }
    public function getSetting()
    {
      $setting = $this->pcConfig->select();
      $res = ['code' => 1, 'data' => $setting, 'msg' => ''];
      return json($res);
    }

    public function updateSetting()
    {
      $params = $this->request->post();
      foreach ($params as $key => $value) {
        $this->pcConfig->where('id', $value['id'])->update(['content' => $value['content']]);
      }
      $res = ['code' => 1, 'data' => true, 'msg' => ''];
      return json($res);
    }

    public function getSettingToObj()
    {
      $setting = $this->pcConfig->select();
      $data = [];
      foreach ($setting as $key => $value) {
        $data[$value['type_str']] = $value['content'];
      }
      $res = ['code' => 1, 'data' => $data, 'msg' => ''];
      return json($res);
    }
}
